﻿using FigureDraw.Diagram;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FigureDraw.Shapes.Effect
{
    public class MyBorder : MyEffect
    {
        public MyBorder()
        { 
        }

        public MyBorder(MyShape shape)
            : base(shape)
        {
        }

        public override MyShape Clone()
        {
            return new MyBorder(originalShape);
        }

        public override void Draw(Graphic.CommonGraphic graphic)
        {
            //Them vo doan nay
            originalShape.StrokeColor = strokeColor;
            originalShape.BrushColor = BrushColor;
            originalShape.StrokeWidth = strokeWidth;
            originalShape.StartPoint = startPoint;
            originalShape.EndPoint = endPoint;
            //Ket thuc them

            base.Draw(graphic);

            MyPoint size = new MyPoint(6, 6);
            //MyColorInfo strokeColor = new MyColorInfo(0, 0, 0);
            strokeColor = new MyColorInfo(0, 0, 0);
            //double strokeWidth = 1.0f;
            //strokeWidth = 1.0f;
            MyColorInfo brushColor = new MyColorInfo(0, 162, 232);

            MyRectInfo rect = MyRectInfo.Convert(originalShape.StartPoint, originalShape.EndPoint);
            MyPoint shapePos = rect.Position;
            MyPoint shapeSize = rect.Size;

            MyPoint p1 = shapePos;
            MyPoint p2 = new MyPoint(shapePos.X + shapeSize.X / 2 - size.X / 2, shapePos.Y);
            MyPoint p3 = new MyPoint(shapePos.X + shapeSize.X - size.X, shapePos.Y);
            MyPoint p4 = new MyPoint(shapePos.X + shapeSize.X - size.X, shapePos.Y + shapeSize.Y / 2 - size.Y / 2);
            MyPoint p5 = new MyPoint(shapePos.X + shapeSize.X - size.X, shapePos.Y + shapeSize.Y - size.Y);
            MyPoint p6 = new MyPoint(shapePos.X + shapeSize.X / 2 - size.X / 2, shapePos.Y + shapeSize.Y - size.Y);
            MyPoint p7 = new MyPoint(shapePos.X, shapePos.Y + shapeSize.Y - size.Y);
            MyPoint p8 = new MyPoint(shapePos.X, shapePos.Y + shapeSize.Y / 2 - size.Y / 2);

            //graphic.DrawEllipse(p1, size, strokeColor, strokeWidth, brushColor);
            //graphic.DrawEllipse(p3, size, strokeColor, strokeWidth, brushColor);
            //graphic.DrawEllipse(p5, size, strokeColor, strokeWidth, brushColor);
            //graphic.DrawEllipse(p7, size, strokeColor, strokeWidth, brushColor);

            //graphic.DrawRectangle(p2, size, strokeColor, strokeWidth, brushColor);
            //graphic.DrawRectangle(p4, size, strokeColor, strokeWidth, brushColor);
            //graphic.DrawRectangle(p6, size, strokeColor, strokeWidth, brushColor);
            //graphic.DrawRectangle(p8, size, strokeColor, strokeWidth, brushColor);

            graphic.DrawEllipse(p1, size, strokeColor, 1.0f, brushColor);
            graphic.DrawEllipse(p3, size, strokeColor, 1.0f, brushColor);
            graphic.DrawEllipse(p5, size, strokeColor, 1.0f, brushColor);
            graphic.DrawEllipse(p7, size, strokeColor, 1.0f, brushColor);

            graphic.DrawRectangle(p2, size, strokeColor, 1.0f, brushColor);
            graphic.DrawRectangle(p4, size, strokeColor, 1.0f, brushColor);
            graphic.DrawRectangle(p6, size, strokeColor, 1.0f, brushColor);
            graphic.DrawRectangle(p8, size, strokeColor, 1.0f, brushColor);
        }

        public override MyShape AttachEffect(MyShape shape)
        {
            return new MyBorder(shape);
        }

        public override MyShape DetachEffect()
        {
            return originalShape;
        }
    }
}
